package cn.cleanarch.infra.idp.pms.domain.dto;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 设计文件版本预览DTO
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class DesignFileVersionPreviewDTO extends DesignFileVersionDTO {

    /**
     * 预览URL
     */
    private String previewUrl;

    /**
     * 预览类型
     */
    private String previewType;

    /**
     * 是否支持预览
     */
    private Boolean canPreview;

    /**
     * 构造函数
     */
    public DesignFileVersionPreviewDTO() {
        super();
    }

    /**
     * 构造函数
     * @param version 版本信息
     * @param previewUrl 预览URL
     */
    public DesignFileVersionPreviewDTO(DesignFileVersionDTO version, String previewUrl) {
        // 复制所有属性
        this.setId(version.getId());
        this.setFileId(version.getFileId());
        this.setVersionNumber(version.getVersionNumber());
        this.setDescription(version.getDescription());
        this.setFileKey(version.getFileKey());
        this.setFileSize(version.getFileSize());
        this.setFileType(version.getFileType());
        this.setFileMd5(version.getFileMd5());
        this.setStatus(version.getStatus());
        this.setVersionStatus(version.getVersionStatus());
        this.setOperationType(version.getOperationType());
        this.setOperatorId(version.getOperatorId());
        this.setCreateTime(version.getCreateTime());
        this.setUpdateTime(version.getUpdateTime());
        
        this.previewUrl = previewUrl;
        this.previewType = getPreviewType(version.getFileType());
        this.canPreview = this.previewType != null && !this.previewType.equals("download");
    }

    /**
     * 根据文件类型获取预览类型
     */
    private String getPreviewType(String fileType) {
        if (fileType == null) {
            return "download";
        }
        
        switch (fileType.toLowerCase()) {
            case "html_zip":
            case "html":
                return "html";
            case "image":
            case "jpg":
            case "jpeg":
            case "png":
            case "gif":
            case "svg":
            case "webp":
                return "image";
            case "pdf":
            case "doc":
            case "docx":
            case "xls":
            case "xlsx":
            case "ppt":
            case "pptx":
                return "document";
            default:
                return "download";
        }
    }
}
